package cn.tedu.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;

public class SocketClient {
	public static void main(String[] args) throws IOException, Exception {
		//开启客户端通道
		SocketChannel sc=SocketChannel.open();
		//设置为非阻塞
		sc.configureBlocking(false);
		//发起连接
		sc.connect(new InetSocketAddress("localhost",8090));
		int i=0;
		while(!sc.isConnected()){
			//试图在此建立连接并且自动计数
			sc.finishConnect();
			//写出数据
			sc.write(ByteBuffer.wrap("hello server".getBytes()));
			//关流
			sc.close();
		}

	}
}
